
package ucm.module;

import air_cp5620.dao.DAO;
import javax.swing.JOptionPane;
import java.sql.*;
import ucm.view.UC_UMV;


public class UC_CreInfoM {

    private DAO dbCon = null;

    public UC_CreInfoM() {
        dbCon = new DAO();
    }


    public void create(String start_city, String end_city, String start_time,String end_time,String ticketcount,String price) {
        String sql = null;
        Connection con = dbCon.getConnection();
        if (con == null) {
            JOptionPane.showMessageDialog(null, "Create connection error!");
        }
        try {
            Statement stmt = con.createStatement(ResultSet.CONCUR_UPDATABLE, ResultSet.CONCUR_UPDATABLE);
            sql = "INSERT INTO tbl_air_info (start_city,end_city,start_time,end_time,ticketcount,price) " +
                    "values('" + start_city + "', '" + end_city + "',date_format('" + start_time + "','%Y-%m-%d %H:%i:%s'),date_format('" + end_time + "','%Y-%m-%d %H:%i:%s')," + ticketcount + "," + price + ")";
            stmt.executeUpdate(sql);
            JOptionPane.showMessageDialog(null, "Create air info successful!");
            UC_UMV uc_umv = new UC_UMV();
            uc_umv.setVisible(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Create air info false！");
            e.printStackTrace();            
        }
    }
}
